<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #d1{
            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>
<body>
    <input id="btn" type="button" value="按钮">
    <input id="removeBtn" type="button" value="删除事件">
    <input type="text" id="ipt">
    <div id="d1">
        <p id="p1">123</p>
    </div>
    <script>
        let d1 = document.getElementById("d1");
        let p1 = document.getElementById("p1");
        let ipt = document.getElementById("ipt");
        // let print = function(){
        //         console.log("DOM2 click");
        //     };
        // document.getElementById("btn").onclick = function(event){
        //     console.log(this,event.target,event.type);
        //     d1.onclick = function(){
        //         console.log("click")
        //     }
        //     d1.addEventListener("click",print);
        // }
        // document.getElementById("removeBtn").onclick = function(){
        //     d1.removeEventListener("click",print);
        // }
        document.body.onclick = function(){
            console.log("body");
        }
        d1.onclick = function(e){
            console.log("d1");
            e.stopPropagation();
        }
        p1.onclick = function(){
            console.log("p1");
        }
        document.body.addEventListener('click',function(){
            console.log("DOM2 body");
        },true)
        d1.addEventListener('click',function(){
            console.log("DOM2 d1");
        },true)
        p1.addEventListener('click',function(){
            console.log("DOM2 p1");
        },true)

        d1.onmouseenter = function(e){
            console.log(e,e.x,e.y)
        }
        // ipt.onkeydown = function(e){
        //     console.log(e.keyCode);
        //     e.preventDefault();
        // }
        // ipt.onkeyup = function(e){
        //     console.log(e.keyCode);
            
        // }
        ipt.onkeypress = function(e){
            console.log(e.keyCode);
            e.preventDefault();
        }
    </script>
</body>
</html>